home *** CD-ROM | disk | FTP | other *** search
- Path: mudskipper.cac.psu.edu!user
- From: fcusack@tdx.org (frank.)
- Newsgroups: comp.lang.c
- Subject: Re: && operator question
- Date: Thu, 15 Feb 1996 18:17:50 -0400
- Organization: Psychic Enemies Network
- Message-ID: <fcusack-1502961817500001@mudskipper.cac.psu.edu>
- References: <4fu69a$b7e@sphinx.Gsu.EDU> <4fuet4$b3r@niktow.canisius.edu> <31232EC0.3CD@visigenic.com>
- NNTP-Posting-Host: mudskipper.cac.psu.edu
-
- In article <31232EC0.3CD@visigenic.com>, Tim O'Neil <toneil@visigenic.com>
- wrote:
-
- > Alan Duchan wrote:
- > > An ANSI conforming compiler will not evaluate expression2 when expression1
- > > is false. Similarly, for
- > > expr1 || expr2
- > >
- > > when expr1 is true, expr2 will not be evaluated.
- >
- > Whoops. I guess my solution isn't the way to write the
- > evaluation (unless you want that effect.) What would be
- > the effect of writing it:
- >
- > ((exp1) || (exp2)) stamt;?
-
- You would have a syntax error b/c you left out the "if". Had you included
- the if, if exp1 evaluates to true, then exp2 is *not* evaluated (and any
- side effects from exp2 thus do not occur) and stamt is executed. If exp1
- evaluates to false, then exp2 is evaluated and if it is true, stamt is
- executed.
-
- So if exp2 were something like i++ then it does not get executed if exp1
- is true, and *i does not get incremented*.
- ~Frank
- -- I am Pentium of Borg. Division is futile. You will be approximated. --
- -- If you build it, they will come --> http://www.tdx.org/~fcusack/ --
- -- PGP key fingerprint: 01 C0 C0 B9 CC 78 67 0F 3F 64 80 65 8B 0F F9 EA --
-